<?php

class Components extends Admin_Controller {

	function __construct()
	{
		parent::__construct();	
		
		$this->aPageJs[] = array(
							'combine_js' => true,
							'base_href' => '/media/js',
							'js' => array('codemirror', 'admin_components'),
							'version' => '1.0'
		);	

		// build up our header_css array
		$this->aPageCss[] = array(
							'combine_css' => true,
							'base_href' => '/media/css',
							'css' => array('codemirror', 'admin_components'),
							'media' => 'all',
							'version' => '1.0'
		);
	}
	
	public function index()
	{
		$this->load->model('db/site_components', 'site_components');
		$this->site_components->component_status = 'LI';
		$qComponents = $this->site_components->get();
		
		$this->aData['qComponents'] = $qComponents;
		
		$this->load->view('platform/'.$this->sPlatform.'/admin/components/index', $this->aData);
	}
	
	public function add_component()
	{
		$this->edit_component();
	}
	
	public function edit_component($iComponentId = NULL)
	{
		$this->load->model('db/site_components', 'site_components');
		
		$oComponent = $this->site_components->get_object();
		
		if($iComponentId !== NULL)
		{
			$this->site_components->component_id = $iComponentId;
			
			$qComponent = $this->site_components->get(1);
			
			$oComponent = $qComponent->num_rows() === 1 ? $qComponent->row(0) : $oComponent;
		}
		
		$this->aData['oComponent'] = $oComponent;
		
		$this->load->view('platform/'.$this->sPlatform.'/admin/components/edit', $this->aData);
	}
}

?>